/*
OpenMVL Matrix Vector Library
Copyright (c) 2009 FluidInteractive (R)
 
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising
from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
 
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must
not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
 
Written by: Nicola Candussi <nicola@fluidinteractive.com>
*/

//element_unary.hpp

#ifndef MVL_ELEMENT_UNARY_HPP
#define MVL_ELEMENT_UNARY_HPP

#include "layout_element_unary.hpp"

namespace mvl {

template<typename E, typename Fn, typename TagFn>
struct element_unary {
    typedef E expr_t;
    typedef typename expr_t::value_type value_type;

    typedef typename expr_t::layout_t expr_layout_t;
    typedef typename expr_layout_t::order order;
    typedef typename layout::layout_element_unary<expr_layout_t, TagFn>::type layout_t;

    template<typename Entry>
    static value_type at(expr_t const& e) {
        return Fn::template apply<Entry>(e, typename Entry::src::tag());
    }
};

//neg
struct tagfn_neg {
    template<typename Tag>
    struct apply : layout::neg_tag<Tag> { };
};

struct fn_neg {

    template<typename Entry, typename E>
    static typename E::value_type apply(E const& e, layout::_v_) {
        return -e.template at<typename Entry::src>();
    } 

    template<typename Entry, typename E>
    static typename E::value_type apply(E const& e, layout::_1_) {
        typedef typename E::value_type value_type;
        return value_type(-1);
    } 
};



} // namespace mvl

#endif

